#include <stdio.h>
#include <string.h>

void reverse_str(char*);
void reverse(char*);

/**
 * 题目：字符串反转，如将字符串 "www.runoob.com" 反转为 "moc.boonur.www"。
*/
int main(int argc, char const *argv[])
{
    char s[] = "www.runoob.com";
    printf("%s\n", s);
    // reverse_str(s);
    reverse(s);
    printf("%s\n", s);
    return 0;
}

void reverse_str(char *str)
{
    char *p;
    int len = 0;
    p = str;
    while (*p != 0)
    {
        len++;
        p++;
    }

    int i = 0;
    char c;
    while(i <= len / 2 - 1)
    {
        c = *(str+i);
        *(str+i) = *(str + len - 1 - i);
        *(str + len - 1 - i) = c;
        i++;
    }
    
}

void reverse(char *str)
{
    int len;
    char *b, *e;
    char c;

    len = strlen(str);

    b = str;
    e = str + len - 1;

    while (b<e)
    {
        c = *b;
        *b = *e;
        *e = c;
        b++;
        e--;
    }
    
}